<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="UTF-8">
	<title>CRM客户关系管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
 	<!-- <link rel="stylesheet" href="/gaoa/Public/css/global.css" media="all"> -->
	<!--<link rel="stylesheet" href="/gaoa/Public/plugins/font-awesome/css/font-awesome.min.css"> -->

	<link rel="stylesheet" href="/gaoa/Public/css/element-ui--index.css">


	<style>
	    *{
	    	font-family: microsoft YaHei;
	    }
		.pull-left {
			float: left;
		}
		.pull-right {
			float: right;
		}
		.container {
			padding: 2px;
		}
		.container > .wrapp >  .el-row {
			margin-bottom: 10px;
		}
		.el-form--inline .el-form-item {
			margin-bottom: 0px;
		}
/*		#app>.wrapp{
			display: none;
		}*/
		
		/*表格条纹样式*/
		.el-table .info-row {
		background: #ffffff;
		}

		.el-table .positive-row {
		background: #c9e5f5;
		}
		.cell img{
			vertical-align: middle;
		}
		
		.el-date-editor.el-input{
			width: 100%;
			max-width: 370px;
		}

		.el-table__body tr.current-row>td{
	      background: rgba(157, 195, 232, 0.7) !important;
	  }

    @media screen and (min-width:1165px) and (max-width:1200px){
      .el-dialog--small {
          width: 70%;
      }
    }

    @media only screen and (max-width:1164px){
      .el-dialog--small {
          width: 85%;
      }
    }  		
	</style>
	<!-- 如果没有 则 提供一些高级的js功能  -->
	<script src="/gaoa/Public/js/advancejs.js"></script>
	<!-- 不支持IE9 及以下的浏览器 -->
	<!--[if lte IE 9]> 
	<script>
		window.location.href="<?php echo U('login/notsupport');?>";
	</script>
	<![endif]-->
	
  <style>
    .el-tabs__header{
      border-top:2px solid #ea4b4b;
      border-bottom: 1px solid #c51f1f;
    }
    .el-dialog .el-tabs__header{
      border-top:none;
    }
    .el-tabs--border-card .el-tabs__item{
      border-left: none;
    }
    .el-tabs--border-card .el-tabs__item.is-active {
      background-color: #fff;
      border-right-color: #d3dce6;
      background: #544b8f;
      color: #fff;
    }
    .el-tabs--border-card .el-tabs__header {
      background-color: #fff;
      margin: 0;
    }
    .container > .wrapp > .a > .el-row {
      margin-bottom: 6px;
    }
    .el-tabs--border-card .el-tabs__content{
      padding:0 9px 5px 9px;
    }
    .el-card, .el-menu--horizontal .el-submenu>.el-menu, .el-tabs--border-card{
      box-shadow: none;
    }
    .el-tabs--border-card{
      border: none;
    }
    .el-tabs__item{
    	font-family: Microsoft YaHei;
    	color:#0d0f10;
    	font-size: 14px;
    }
    .el-dialog__body{
      color: rgb(72, 87, 106);
      font-size: 14px;
      /*padding: 30px 20px;*/
      padding: 30px 20px 6px 20px;
    }
  </style>

</head>
<body>
	
	
	<div id="app" class="container">
		<div class="wrapp" v-show="show" style="display:none;">
			<div class="a">
				<el-row>
        	<el-col :span="24">
          	<el-form :inline="true" ref="searchForm" :model="searchForm">
          		<el-form-item v-show="departName=='总部'">
	              <el-select size="small" style="width:150px;" v-model="searchForm.belongs_department" clearable filterable allow-create placeholder="所属部门">
                  <el-option v-for="department in belongsDepartment" :label="department.name" :value="department.name"></el-option>
	              </el-select>
			  		  </el-form-item>
			  		  
			  		  <el-form-item>
	              <el-select size="small" style="width:150px;" v-model="searchForm.type" clearable filterable allow-create placeholder="所属类别">
                  <el-option v-for="(value,key) in type" :label="value" :value="value"></el-option>
	              </el-select>
			  		  </el-form-item>

			  		  <el-form-item prop="name" style="width:150px">
			  		    <el-input v-model="searchForm.name" size="small" placeholder="用品名称"></el-input>
			  		  </el-form-item>

	            <el-form-item>
	              <el-tooltip content="填写或者选择好筛选条件后点击此按钮" placement="bottom-start">
	                <el-button type="info" size="small" icon="search" @click="loadDatalist">查询</el-button>
	              </el-tooltip> 
	            </el-form-item>
             
              <el-form-item>
	              <el-tooltip content="清空搜索框并刷新表格数据" placement="bottom-start">
	                <el-button size="small" @click="resetBack">重置</el-button>
	              </el-tooltip>
              </el-form-item>

	            <el-form-item>
	              <el-tooltip content="点击刷新当前页面" placement="right">
	                <el-button @click="refresh" size="small" type="danger">刷新</el-button>
	              </el-tooltip>
	            </el-form-item>
            </el-form>
          </el-col>
			  </el-row>

			  <el-row>
        	<el-col :span="24">
	          <el-table v-loading="dataLoad" :data="dataList"
                @selection-change="handleChange"
	              element-loading-text="<?php echo L('DATA_LOGIN');?>"
	              empty-text="暂无数据！"
	              highlight-current-row ref="select" border>
              <el-table-column type="selection" width="55"></el-table-column>

			  	    <el-table-column label="<?php echo L('INDEX');?>" type="index" width="65" >
			  	    </el-table-column>
			  	    
			  	    <el-table-column  align="center" prop="belongs_department" label="部门">
	            </el-table-column>

	            <el-table-column  align="center" prop="name" label="用品名称">
	            </el-table-column>

			  	    <el-table-column  align="center" prop="type" label="所属类别">
			  	    </el-table-column>

              <el-table-column  align="center" prop="unit" label="单位">
              </el-table-column>

              <el-table-column  align="center" prop="specification" label="规格">
              </el-table-column>
              
              <!--<el-table-column  align="center" prop="price" label="单价">
              </el-table-column>-->

              <el-table-column  align="center" prop="attributes" label="物品属性">
              	<template scope="scope">
				          {{ getType(scope.row.attributes, 'attributes') }}
				        </template>
              </el-table-column>
              <el-table-column label="是否启用" :context="_self" align="center" prop="status">
					      <template scope="scope">
  							<div>
  						        <el-switch
  								  v-model="scope.row.switch"
  								  on-color="#13ce66"
  								  off-color="#ff4949" 
  								  @change="switchHandle(scope.$index, scope.row)">
  								</el-switch>
  							</div>
                         </template>
					    </el-table-column>
	          </el-table>
          </el-col>
			  </el-row>

			  <el-row>
			  	<el-col :span="12">
			      <div class="grid-content bg-purple">
              <span class="wrapper">
                <el-tooltip content="至少选择一条信息再点击删除" placement="bottom-start">
                  <el-button size="small" @click="handleDeletes" type="danger">删除</el-button>
                </el-tooltip>
                <el-tooltip content="点击新增一个录入资料申请" placement="right">
                  <el-button size="small" @click="openDialog('add')" type="primary">录入资料</el-button>
                </el-tooltip>
              </span>
			      </div>
			    </el-col>
			  	<el-col :span="12" >
			      <div class="grid-content bg-purple-light pull-right">
			        <!-- page -->
			        <el-pagination
  @current-change="handleCurrentPageChange"
  :current-page="currentPage"
  layout="total, prev, pager, next, jumper"
  :total="total"
  :page-size="pageSize"
  ref="pagination"
  >
</el-pagination>
			        <!-- / page -->
			      </div>
			    </el-col>
			  </el-row>
			</div>
			<div class="dialogWrapper" v-show="show" style="display: none">
			  <!-- 新增 -->
			  <el-dialog title="新增用品资料" v-model="addFormDialog">
  <el-form  ref="addForm" :label-width="dialogLabelWidth" :model="addForm" :rules="addRules">
    <el-row>
      <el-col :span="11" >
        <el-form-item label="名称" prop="name" >
          <el-input v-model="addForm.name" placeholder="请输入物品名称"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="11">
        <el-form-item label="类别" prop="type" >
          <el-select v-model="addForm.type" placeholder="请选择物品分类">
            <el-option v-for="(value,key) in type"  :label="value" :value="value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      
    </el-row>

    <el-row>
      <el-col :span="11">
        <el-form-item label="单位" prop="unit" >
          <el-input v-model="addForm.unit" placeholder="请输入物品单位,如:台 /个"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="11">
        <el-form-item label="规格" prop="specification" >
          <el-input v-model="addForm.specification" placeholder="请填写规格:品牌/颜色/尺寸"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
 
    <el-row>
      <el-col :span="11">
        <el-form-item label="属性" prop="attributes" >
          <el-select v-model="addForm.attributes" placeholder="请选择物品属性">
            <el-option v-for="(value,key) in attributes"  :label="value" :value="key"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>

  <div slot="footer" class="dialog-footer">
    <el-button @click="closeDialog('add')">取 消</el-button>
 <el-button type="primary" v-show="!addFormSubmitStatus" @click="addFormSubmit(page.addFormUrl, 'add')" >确 定</el-button>
 <el-button type="primary" v-show="addFormSubmitStatus" :loading="true" >添加中</el-button>
  </div>

</el-dialog>

		    <!-- / 新增 -->
			</div>
		</div>
	</div>

	<script src="/gaoa/Public/js/vue.min.js"></script>
  <script src="/gaoa/Public/js/element-ui--index.js"></script>
	<script src="/gaoa/Public/js/vue-resource.min.js"></script>

	<!-- vue 通用部分  -->
	<script src="/gaoa/Public/js/vueHooks.js"></script>
	<script src="/gaoa/Public/js/vueMethods.js"></script>
	<script src="/gaoa/Public/js/vueOption.js"></script>
	<script src="/gaoa/Public/js/vueCommonLogic.js?b=d"></script>
	<script>
		var page = {
			addFormUrl:"<?php echo U('add');?>",
			editFormUrl:"<?php echo U('edit');?>",
			listUrl:"<?php echo U('getList');?>",
			deleteUrl:"<?php echo U('delete');?>",
			pageSize:<?php echo ($pageSize); ?>
		}
		window.defaultOption = new VueOption();

		// setCommonLogin 还可以再细分
		setCommonLogic(window.defaultOption);


	</script>

	<!-- / vue 通用部分  -->


	<script>
		
		
	</script>


	
<script>
	window.defaultOption.setDatas({
		multipleSelection: [],
		dialogLabelWidth:"120px",
    dataList:[],
    type:<?php echo json_encode($type);?>,
    attributes:<?php echo json_encode($attributes);?>,
    belongsDepartment:<?php echo json_encode($belongsDepartment);?>,
    departName:<?php echo json_encode($departName);?>,
    statusForm:{
       id:'',
       status:'1',
    },
    addRules:{
			name:[
				{pattern:/^([^\s]){1,10}$/,message:'不超过10个汉字！不能使用空格',required: true},
			],
			type:[
      {required: true, message: '请输入物品类别', trigger: 'blur'},
			],
			unit:[
      {pattern:/^([^\s]){1,4}$/,message:'不超过4个汉字！不能使用空格',required: true},
			],
			specification:[
      {pattern:/^([^\s]){1,42}$/,message:'不超过42个汉字！不能使用空格',required: true},
			],
			
			attributes:[
      {required: true, message: '请选择物品属性'},
			]
		},
	}).setForm('add',{
    name:"",
    type:"",
    unit:"",
    specification:"",
    attributes:"",
    belongs_department:'',
    info_status:"1",
  },true).setForm('search',{
  	belongs_department:<?php echo json_encode($departName);?>,
		type:"",
    name:'',
	}).setMethod('resetBack',function(){
    window.location.href="<?php echo U('index');?>";
  }).setMethod('getType', function(type, field){
 		return this[field][type];
  }).setMethod('handleChange', function(val){
	  this.multipleSelection = val; //点击勾选用这个
		//点击选中用这个 开始
		/*this.deleteArrAllItem('multipleSelection');
		this.multipleSelection.push(val) ;*/
		//点击选中用这个 结束
	    
	}).setMethod('beforeList',function(dataList){
		var vmThis = this;
		dataList.forEach(function(currentValue, index){
           // currentValue['type']     = parseInt(currentValue['type']);
			//currentValue['typeText'] = vmThis.typeList[currentValue['type']];
			// currentValue['zone']     = vmThis.zoneList[currentValue['zone_id']];
  		    currentValue['switch']   = currentValue.status==1?true:false;
            currentValue.status = parseInt(currentValue.status);
		})
		return dataList;

	}).setMethod('switchHandle',function(index,row){
	    row.status=row.switch?'0':'1';
	    this.initObject(this.statusForm, row);
	    this.statusIndex=index;
	    var vmThis =this;
	    this.$http.post(page.editFormUrl,this.statusForm).then(function(response){
	    	
	    }).catch(function(response){
	    	vmThis.$message({
	    		message:'状态更改失败',
	    		type:'error'
	    	});
	    	vmThis.dataList[vmThis.statusIndex].switch = !vmThis.dataList[vmThis.statusIndex].switch;
	    });
    }).setMethod("handleDeletes", function(url){
	  if(this.multipleSelection.length != 1){
		  this.$message.error('请选择一条信息');
		  return false;
	  }else{
		  if (!arguments[2]) {
			  url= this.page.deleteUrl;
		  }
		  var selectedIds = new Array();
		  for(var i=0; i<this.multipleSelection.length; i++){
			  selectedIds[i] = this.multipleSelection[i].id;
		  }
		  var vmThis = this;
		  this.$confirm('确定删除?', '提示', {
			  confirmButtonText: '确定',
			  cancelButtonText: '取消',
			  type: 'warning'
		  }).then(function(){
			  vmThis.$http.post(url, {ids:selectedIds}).then(function(response){
				  vmThis.$message({
					  type: 'success',
					  message: '删除成功!'
				  });
				  vmThis.loadDatalist();
			  }, function(response){
				  vmThis.$message({
					  type: 'error',
					  message: '该用品资料已在使用中，请不要删除！'
				  });
			  })
		  }).catch(function() {
			  vmThis.$message({
				  type: 'info',
				  message: '已取消操作'
			  });
		  });
	  }

  });
</script>

	<script>
	//改modal

		window.defaultVm = new Vue(window.defaultOption.getOption()).$mount('#app');
	</script>
</body>
</html>